package com.example.lawyer.factory;

import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.ListView;

import androidx.annotation.RequiresApi;

public class AutoHeightListTool {



    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public void ListViewHeightTool(ListView gridView, int l)
    {
        ListAdapter adapter = gridView.getAdapter();
        if(adapter==null)
        {
            return;
        }

        int total = 0;
        for(int a=0;a<adapter.getCount();a+=l)
        {
            View item = adapter.getView(a,null,gridView);
            item.measure(0,0);
            int measuredHeight = item.getMeasuredHeight();
            total+=measuredHeight;
        }

        ViewGroup.LayoutParams layoutParams = gridView.getLayoutParams();
        layoutParams.height = total;
        gridView.setLayoutParams(layoutParams);
    }

}
